package edu.ihs.lhpy.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import edu.ihs.lhpy.action.UserAction;
import edu.ihs.lhpy.domain.*;
import edu.ihs.lhpy.service.*;

public class InitServletContextListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public InitServletContextListener() {
    	
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
    	ServletContext application = arg0.getServletContext();
    	//获取application 容器
    	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(application);
    	//得到PrivilegeService对象实例
    	PrivilegeService privilegeService = (PrivilegeService) ac.getBean("privilegeServiceImpl");
//    	UserAction userAction = (UserAction) ac.getBean("userAction");
//    	System.out.println(userAction.getModel().getName()+"---------------");
    	//准备所有顶级菜单
    	List<Privilege> topPrivilegeList = privilegeService.findTopList();
    	application.setAttribute("topPrivilegeList", topPrivilegeList);
//    	System.out.println("====已准备好顶级菜单数据=====");
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
    	
    }
	
}
